package ioTest;

import java.io.BufferedOutputStream;
import java.io.BufferedReader;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.OutputStreamWriter;
import java.io.Writer;


public class FileTest {

	
	public static void writeFile() throws IOException {
	
//		Writer out = new OutputStreamWriter(new FileOutputStream("d:/jobdone/x.txt"),"utf-8");
//		for(int i=0; i<10; i++){
//			out.write("第"+i+"行\n");
//		}
//		out.close();
		
		FileOutputStream outSTr = new FileOutputStream("d:/jobdone/x.txt");   
		BufferedOutputStream Buff = new BufferedOutputStream(outSTr); ;   
		for (int i = 0; i < 11; i++) {   
			Buff.write("威风".getBytes());   
		}   
		Buff.flush();   
		Buff.close();   
		return;
	}
	public static void readFile(String fileName) throws IOException{  
		BufferedReader br = new BufferedReader(new InputStreamReader(new FileInputStream(fileName),"utf-8"));
		String data = null;
		while((data = br.readLine())!=null){
			System.out.println(data);
		}
	}
	public static void delFile(String fileName) {
		File file = new File(fileName);
		if(file.exists())
			file.delete();
	}
	public static void mkFile(String dirName,String fileName){
		File file = new File(dirName);
		if(!file.exists())
			file.mkdirs();
//		File f = new File(fileName);
		System.out.println("done");
	}
	public static void writeFile(String dirName,String fileName,String content) throws IOException {
		File f = new File(dirName+fileName);
		if(f.exists()){
			f.delete();
		}
		File file = new File(dirName);
		if(!file.exists())
			file.mkdirs();
		Writer out = new OutputStreamWriter(new FileOutputStream(dirName+fileName),"utf-8");
		out.write(content);
		out.close();
		return;
	}
	public static void main(String[] args) {
		try {
			writeFile("d:/jobdone/x/","x.txt","asdfasdf发生的发生的法");
			writeFile();
		} catch (Exception e) {
			e.printStackTrace();
		}
		
	}
}
